/*
=======================================================================

  BOTS Team Join menu

=======================================================================
*/
#include "ui_local.h"
#include "ui_BOTS.h"

#define BOTS_TEAMJOINMENU_MALE		1
#define BOTS_TEAMJOINMENU_FEMALE	2
#define BOTS_TEAMJOINMENU_AUTOJOIN	3
#define BOTS_TEAMJOINMENU_OBSERVER	4

typedef struct 
{
  menuframework_s menu;  

  menutext_s	title;
  menutext_s	male;
  menutext_s	female;
  menutext_s	autojoin;
  menutext_s	observer;
  menutext_s	cancel;
} BOTSTeamJoinMenu_t;

static BOTSTeamJoinMenu_t s_BOTSTeamJoinMenu;

/*
=================
BOTS_TeamJoinMenu_Event
callback routine
=================
*/
void BOTS_TeamJoinMenu_Event( void *ptr, int notification ) 
{
	char menuAction[100];
	menuAction[0] = '\0';

	if( notification != QM_ACTIVATED )
		return;

	// any event will kill the menu
	UI_PopMenu();

	switch( ((menucommon_s*)ptr)->id ) 
	{
	case BOTS_CANCEL:
		break;
	case BOTS_TEAMJOINMENU_MALE:
		strcpy(menuAction, "Men");
		break;
	case BOTS_TEAMJOINMENU_FEMALE:
		strcpy(menuAction, "Women");
		break;
	case BOTS_TEAMJOINMENU_AUTOJOIN:
		strcpy(menuAction, "Random");
		break;
	case BOTS_TEAMJOINMENU_OBSERVER:
		strcpy(menuAction, "Observer");
		break;

	// oops - not a valid choice
	default:
		Com_Printf("%i is not a valid choice\n", ((menucommon_s*)ptr)->id);
		break;
	}

	if (menuAction[0] != '\0')
		trap_Cmd_ExecuteText( EXEC_APPEND, va("UI_to_server_rejoin_menu %s\n", menuAction));
}

/*
=================
BOTS_TeamJoinMenu_Init
=================
*/
void BOTS_TeamJoinMenu_Init() 
{
	int		y;

	memset( &s_BOTSTeamJoinMenu, 0 ,sizeof(BOTSTeamJoinMenu_t) );
	s_BOTSTeamJoinMenu.menu.wrapAround = qtrue;
	s_BOTSTeamJoinMenu.menu.fullscreen = qfalse;

	y = 96;
	s_BOTSTeamJoinMenu.title.generic.type	= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.title.generic.flags	= QMF_CENTER_JUSTIFY;
	s_BOTSTeamJoinMenu.title.generic.x		= 320;
	s_BOTSTeamJoinMenu.title.generic.y		= y;
	s_BOTSTeamJoinMenu.title.string			= "TEAM SELECTION MENU";
	s_BOTSTeamJoinMenu.title.color			= color_bots_menu;
	s_BOTSTeamJoinMenu.title.style			= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSTeamJoinMenu.male.generic.type		= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.male.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSTeamJoinMenu.male.generic.x			= 320;
	s_BOTSTeamJoinMenu.male.generic.y			= y;
	s_BOTSTeamJoinMenu.male.generic.id			= BOTS_TEAMJOINMENU_MALE;
	s_BOTSTeamJoinMenu.male.generic.callback	= BOTS_TeamJoinMenu_Event; 
	s_BOTSTeamJoinMenu.male.string				= "MEN";
	s_BOTSTeamJoinMenu.male.color				= color_bots_menu;
	s_BOTSTeamJoinMenu.male.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSTeamJoinMenu.female.generic.type		= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.female.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSTeamJoinMenu.female.generic.x			= 320;
	s_BOTSTeamJoinMenu.female.generic.y			= y;
	s_BOTSTeamJoinMenu.female.generic.id		= BOTS_TEAMJOINMENU_FEMALE;
	s_BOTSTeamJoinMenu.female.generic.callback	= BOTS_TeamJoinMenu_Event; 
	s_BOTSTeamJoinMenu.female.string			= "WOMEN";
	s_BOTSTeamJoinMenu.female.color				= color_bots_menu;
	s_BOTSTeamJoinMenu.female.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSTeamJoinMenu.autojoin.generic.type		= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.autojoin.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSTeamJoinMenu.autojoin.generic.x			= 320;
	s_BOTSTeamJoinMenu.autojoin.generic.y			= y;
	s_BOTSTeamJoinMenu.autojoin.generic.id			= BOTS_TEAMJOINMENU_AUTOJOIN;
	s_BOTSTeamJoinMenu.autojoin.generic.callback	= BOTS_TeamJoinMenu_Event; 
	s_BOTSTeamJoinMenu.autojoin.string				= "AUTOJOIN";
	s_BOTSTeamJoinMenu.autojoin.color				= color_bots_menu;
	s_BOTSTeamJoinMenu.autojoin.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSTeamJoinMenu.observer.generic.type		= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.observer.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSTeamJoinMenu.observer.generic.x			= 320;
	s_BOTSTeamJoinMenu.observer.generic.y			= y;
	s_BOTSTeamJoinMenu.observer.generic.id			= BOTS_TEAMJOINMENU_OBSERVER;
	s_BOTSTeamJoinMenu.observer.generic.callback	= BOTS_TeamJoinMenu_Event; 
	s_BOTSTeamJoinMenu.observer.string				= "OBSERVER";
	s_BOTSTeamJoinMenu.observer.color				= color_bots_menu;
	s_BOTSTeamJoinMenu.observer.style				= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_BOTSTeamJoinMenu.cancel.generic.type		= MTYPE_PTEXT;
	s_BOTSTeamJoinMenu.cancel.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_BOTSTeamJoinMenu.cancel.generic.x			= 320;
	s_BOTSTeamJoinMenu.cancel.generic.y			= y;
	s_BOTSTeamJoinMenu.cancel.generic.id		= BOTS_CANCEL;
	s_BOTSTeamJoinMenu.cancel.generic.callback	= BOTS_TeamJoinMenu_Event; 
	s_BOTSTeamJoinMenu.cancel.string			= "CANCEL";
	s_BOTSTeamJoinMenu.cancel.color				= color_bots_menu;
	s_BOTSTeamJoinMenu.cancel.style				= UI_CENTER|UI_SMALLFONT;

	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.title );
	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.male );
	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.female );
	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.autojoin );
	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.observer );
	Menu_AddItem( &s_BOTSTeamJoinMenu.menu, &s_BOTSTeamJoinMenu.cancel );
}

void BOTS_TeamJoinMenu_f( void ) 
{
	// force as top level menu
	uis.menusp = 0;

	// if autojoin is ON we don't want to show this menu
	if ( (int)trap_Cvar_VariableValue("g_teamAutoJoin") == 1 )
	{
		trap_Cmd_ExecuteText( EXEC_APPEND, va("UI_to_server_rejoin_menu Random\n"));
		return;
	}		

	// set menu cursor to a nice location
	uis.cursorx = 319;
	uis.cursory = 80;

	// setup the menu structure
	BOTS_TeamJoinMenu_Init();

	// show the menus
	UI_PushMenu( &s_BOTSTeamJoinMenu.menu );
}
